<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./react/react.development.js"></script>
    <script src="./react/react-dom.development.js"></script>
    <script src="./react/babel.min.js"></script>
    <script src="./react/prop-types.js"></script>
    <script src="./react/lodash.min.js"></script>
    <script src="./react/immutable.min.js"></script>

</head>
<body>
<div id="app"></div>
<script type="text/babel">

    let app = document.querySelector('#app');
    let root = ReactDOM.createRoot(app);

    class Welcome extends React.Component{
        state = {
            msg:'hello',
            city:'南昌',
            gender: '女',
            fruits: ['苹果','西瓜']
        }
        handleChange = (ev) => {
            if(ev.target.checked){
                this.setState({
                    fruits:[...this.state.fruits,ev.target.value]
                })
            }else{
                let fruits = [...this.state.fruits]
                fruits.splice(fruits.indexOf(ev.target.valueOf),1)
                this.setState({fruits})
            }
        }

        render(){
            return(
                <div>
                    <input type="checkbox"  value="香蕉"  checked={this.state.fruits.includes('香蕉')}  onChange={this.handleChange}/>香蕉
                    <input type="checkbox"  value="苹果"   checked={this.state.fruits.includes('苹果')}  onChange={this.handleChange}/>苹果
                    <input type="checkbox"  value="西瓜" checked={this.state.fruits.includes('西瓜')} onChange={this.handleChange}/>西瓜
                    <input type="checkbox"  value="葡萄"  checked={this.state.fruits.includes('葡萄')} onChange={this.handleChange}/>葡萄
                    {this.state.fruits}
                </div>
            )
        }
    }

    let element = (<Welcome/>)
    root.render(element);

</script>
</body>
</html>